#pragma once

#include "qtree.h"

namespace micro{


namespace utils
{

	 
template<class Key, class Val>
struct Pair
{
	typename Key key;
	typename Val val;
	Pair(const Key & k,Val & v)//:key(k), val(v)
	{
		key = k;
		val = v;
	}
};


template<class T>
class QMapCompareHelper 
{
public:
	static bool IsEqual(T & t1, T & t2)
	{ 
		if(   t1.key == t2.key ) { /* t1.val = t2.val; */ return true; } 
		return false;
	}
	static bool IsLess(T & t1, T & t2) { return t1.key < t2.key;  }
};

template<>
class QMapCompareHelper< Pair<QString, int>  > 
{
public:
	static bool IsEqual(Pair<QString, int> & t1, Pair<QString, int> & t2)
	{ 
		if( 0 == t1.key.CompareNoCase(t2.key) ) { t1.val = t2.val; return true; } 
		return false;
	}
	static bool IsLess(Pair<QString, int> & t1, Pair<QString, int>  & t2) { return t1.key < t2.key; }
};

template<class Key, class Val, class TEqual = QMapCompareHelper< Pair<Key, Val> > > 
class QMap: public QTree<   Pair<Key, Val> , TEqual >
{

public:
	 //QMap(){ }
	 //~QMap(){ }
	 void Add(Key & k, Val & v)
	 {
		 Pair<Key, Val>   p(k,v);
		 
		 QTree::Add(p);
	 }
	 bool Find(const Key & k, Val & v)
	 {		  
		 Pair<Key, Val>   p(k,v);
		 
		 bool bo = QTree::Find(p);	 //cu setare v  pe egal cu ajutorul lui QMapCompareHelper< Pair<QString, int>  > 
	 
		 //if(bo)
			 v = p.val;

		 return bo;
	 }
	 void Remove(const Key &k)
	 {

		 Val v;
		 
		 if(Find(k,v))
		 {
			 Pair<Key, Val>   p(k,v);
			// QTree::Remove(p);
		 }

	 }
	 //void RemoveAll();
	  
};
 

}//namespace

}//micro